<?php
namespace bytefly\yii2common\widgets\lasttab;

use InvalidArgumentException;
use yii\base\Widget;

class LastTab extends Widget{

    /** 当使用不同参数访问 lastTab 时，记录当前访问的页面 ID */
    public $uniqueId;

    public function init()
    {
        parent::init();

        if ($this->uniqueId == null){
            throw new InvalidArgumentException("LstTab 需要设置 uniqueId 属性");
        }

        LastTabAsset::register($this->getView());        

        $key = "lasttab_view_{$this->uniqueId}";
        $js = <<< JS
        $(function() { 
            var currentKey = "$key"    
            registerLastTabHandler(currentKey)
            switchToTab(currentKey)
        });
        JS;
        $this->getView()->registerJs($js);
    }
}
?>